package com.societyGames.flashForms
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;

	public class SingleChildContainer extends Sprite
	{
		protected var _child:DisplayObject;
		
		public function get child():DisplayObject
		{
			return this._child;
		}
		
		public function set child(value:DisplayObject):void
		{
			if (this._child != value)
			{
				var changeSize:IChangeSize;
				//Remove the old one.
				if (this._child != null)
				{
					changeSize = this._child as IChangeSize;
					if (changeSize != null)
					{
						changeSize.sizeChangedEventObject.removeEventListener(childSizeChangedHandler);
					}
					this.removeChild(this._child);
				}
				this._child = value;
				//Deal with the new one.
				if (this._child != null)
				{	
					changeSize = this._child as IChangeSize;
					if (changeSize != null)
					{
						changeSize.sizeChangedEventObject.addEventListener(childSizeChangedHandler);
					}
					this.addChild(this._child);
				}
				childSizeChangedHandler(null);
			}
		}
		
		protected function childSizeChangedHandler(event:Event):void
		{
		}
	}
}